home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / corelib / ncbimem.h < prev    next >
Text File  |  1996-07-05  |  7KB  |  202 lines

  1. /*   ncbimem.h
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE                          
  5. *               National Center for Biotechnology Information
  6. *                                                                          
  7. *  This software/database is a "United States Government Work" under the   
  8. *  terms of the United States Copyright Act.  It was written as part of    
  9. *  the author's official duties as a United States Government employee and 
  10. *  thus cannot be copyrighted.  This software/database is freely available 
  11. *  to the public for use. The National Library of Medicine and the U.S.    
  12. *  Government have not placed any restriction on its use or reproduction.  
  13. *                                                                          
  14. *  Although all reasonable efforts have been taken to ensure the accuracy  
  15. *  and reliability of the software and data, the NLM and the U.S.          
  16. *  Government do not and cannot warrant the performance or results that    
  17. *  may be obtained by using this software or data. The NLM and the U.S.    
  18. *  Government disclaim all warranties, express or implied, including       
  19. *  warranties of performance, merchantability or fitness for any particular
  20. *  purpose.                                                                
  21. *                                                                          
  22. *  Please cite the author in any work or product based on this material.   
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  ncbimem.h
  27. *
  28. * Author:  Gish, Kans, Ostell, Schuler
  29. *
  30. * Version Creation Date:   1/1/91
  31. *
  32. * $Revision: 2.14 $
  33. *
  34. * File Description: 
  35. *       prototypes for ncbi memory functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. * 9-19-91  Schuler     Modified existing prototypes for ANSI-resemblance
  42. * 9-19-91  Schuler     Added new prototypes for Windows ANSI-like functions
  43. * 9-19-91  Schuler     Changed all functions to _cdecl calling convention
  44. * 04-15-93 Schuler     Changed _cdecl to LIBCALL
  45. * 05-21-93 Schuler     Nlm_MemFreeTrace added for debugging MemFree
  46. * 06-14-93 Schuler     Added dll_Malloc and dll_Free
  47. *
  48. * ==========================================================================
  49. */
  50. #ifndef _NCBIMEM_
  51. #define _NCBIMEM_
  52.  
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56.  
  57. /* ======== PROTOTYPES ======== */
  58.  
  59. void * LIBCALL Nlm_MemNew PROTO((Nlm_sizeT size));
  60. void * LIBCALL Nlm_MemGet PROTO((Nlm_sizeT size, unsigned int flags));
  61. void * LIBCALL Nlm_MemMore PROTO((void *ptr, Nlm_sizeT size));
  62. void * LIBCALL Nlm_MemExtend PROTO((void *ptr, Nlm_sizeT size, Nlm_sizeT oldsize));
  63. void * LIBCALL Nlm_MemFree PROTO((void *ptr));
  64. void * LIBCALL Nlm_MemCopy PROTO((void *dst, const void *src, Nlm_sizeT bytes));
  65. void * LIBCALL Nlm_MemMove PROTO((void *dst, const void *src, Nlm_sizeT bytes));
  66. void * LIBCALL Nlm_MemFill PROTO((void *ptr, int value, Nlm_sizeT bytes));
  67. void * LIBCALL Nlm_MemDup PROTO((const void *orig, Nlm_sizeT size));
  68.  
  69. #if (defined(OS_MAC) || defined(WIN_MSWIN) || defined(MSC_VIRT))
  70. Nlm_Handle  LIBCALL Nlm_HandNew PROTO((Nlm_sizeT size));
  71. Nlm_Handle  LIBCALL Nlm_HandGet PROTO((Nlm_sizeT size, Nlm_Boolean clear_out));
  72. Nlm_Handle  LIBCALL Nlm_HandMore PROTO((Nlm_Handle hnd, Nlm_sizeT size));
  73. Nlm_Handle  LIBCALL Nlm_HandFree PROTO((Nlm_Handle hnd));
  74. void *LIBCALL Nlm_HandLock PROTO((Nlm_Handle hnd));
  75. void *LIBCALL Nlm_HandUnlock PROTO((Nlm_Handle hnd));
  76. #endif
  77.  
  78. #ifdef WIN16
  79. void *  LIBCALL win16_Malloc (Nlm_sizeT bytes);
  80. void *  LIBCALL win16_Calloc (Nlm_sizeT items, Nlm_sizeT size);
  81. void *  LIBCALL win16_Realloc (void *ptr, Nlm_sizeT size);
  82. void    LIBCALL win16_Free (void *ptr);
  83. #endif
  84.  
  85. #ifdef WIN_MAC
  86. #ifdef USE_MAC_MEMORY
  87. void *mac_Malloc  PROTO((Nlm_sizeT size));
  88. void *mac_Calloc  PROTO((Nlm_sizeT nmemb, Nlm_sizeT size));
  89. void *mac_Realloc PROTO((void *ptr, Nlm_sizeT size));
  90. void  mac_Free    PROTO((void *ptr));
  91. #endif
  92. #endif
  93.  
  94. /* ========= MACROS ======== */
  95.  
  96. /* low-level ANSI-style functions */
  97. #ifdef WIN16
  98. #define Nlm_Malloc  win16_Malloc
  99. #define Nlm_Calloc  win16_Calloc
  100. #define Nlm_Realloc win16_Realloc
  101. #define Nlm_Free    win16_Free
  102. #define Nlm_MemSet  _fmemset
  103. #define Nlm_MemCpy  _fmemcpy
  104. #define Nlm_MemChr  _fmemchr
  105. #define Nlm_MemCmp  _fmemcmp
  106. #else
  107. #ifdef USE_MAC_MEMORY
  108. #define Nlm_Malloc  mac_Malloc
  109. #define Nlm_Calloc  mac_Calloc
  110. #define Nlm_Realloc mac_Realloc
  111. #define Nlm_Free    mac_Free
  112. #define Nlm_MemSet  memset
  113. #define Nlm_MemCpy  memcpy
  114. #define Nlm_MemChr  memchr
  115. #define Nlm_MemCmp  memcmp
  116. #else
  117. #define Nlm_Malloc  malloc
  118. #define Nlm_Calloc  calloc                                         
  119. #define Nlm_Realloc realloc
  120. #define Nlm_Free    free
  121. #define Nlm_MemSet  memset
  122. #define Nlm_MemCpy  memcpy
  123. #define Nlm_MemChr  memchr
  124. #define Nlm_MemCmp  memcmp
  125. #endif
  126. #endif
  127.  
  128. #define Malloc  Nlm_Malloc
  129. #define Calloc  Nlm_Calloc
  130. #define Realloc Nlm_Realloc
  131. #define Free    Nlm_Free
  132. #define MemSet  Nlm_MemSet
  133. #define MemCpy  Nlm_MemCpy
  134. #define MemChr  Nlm_MemChr
  135. #define MemCmp  Nlm_MemCmp
  136.  
  137. /*** High-level NCBI functions ***/
  138.  
  139. /* Fake handle functions with pointer functions */
  140.  
  141. #if !( defined(OS_MAC) || defined(WIN_MSWIN) || defined(MSC_VIRT))
  142. #define Nlm_HandNew(a)    Nlm_MemNew(a)    
  143. #define Nlm_HandGet(a,b)  Nlm_MemGet(a,b)
  144. #define Nlm_HandMore(a,b) Nlm_MemMore(a,b)
  145. #define Nlm_HandFree(a)   Nlm_MemFree(a)
  146. #define Nlm_HandLock(a)   (a)
  147. #define Nlm_HandUnlock(a) NULL
  148. #endif
  149.  
  150. /* Pointer functions */
  151. #define MemNew(x)     Nlm_MemGet(x,MGET_CLEAR|MGET_ERRPOST)
  152. #define MemGet(x,y)   Nlm_MemGet(x,(unsigned int)(y))
  153. #define MemFree       Nlm_MemFree
  154. #define MemMore       Nlm_MemMore
  155. #define MemExtend     Nlm_MemExtend
  156. #define MemCopy       Nlm_MemCopy
  157. #define MemMove       Nlm_MemMove
  158. #define MemFill       Nlm_MemFill
  159. #define MemDup        Nlm_MemDup
  160.  
  161. #define HandNew     Nlm_HandNew
  162. #define HandGet     Nlm_HandGet
  163. #define HandMore    Nlm_HandMore
  164. #define HandFree    Nlm_HandFree
  165. #define HandLock    Nlm_HandLock
  166. #define HandUnlock  Nlm_HandUnlock
  167.  
  168.  
  169. #if defined(WIN_MSWIN) && defined(_DEBUG)
  170. void * LIBCALL Nlm_MemFreeTrace (void *, const char*, const char*, int);
  171. #undef MemFree
  172. #define MemFree(_ptr_)  Nlm_MemFreeTrace(_ptr_,THIS_MODULE,THIS_FILE,__LINE__)
  173. #endif
  174.  
  175.  
  176. #ifdef _WINDLL
  177. void * dll_Malloc (Nlm_sizeT bytes);
  178. void   dll_Free (void *pMem);
  179. #else
  180. #define dll_Malloc(x)    (void*)Nlm_Malloc(x)
  181. #define dll_Free(x)    Nlm_Free((void*)(x))
  182. #endif
  183.  
  184.  
  185.  
  186. /* flags for MemGet */
  187. #define MGET_CLEAR    0x0001
  188. #define MGET_ERRPOST  0x0004
  189.  
  190.  
  191. /* obsolete */
  192. #define MG_CLEAR    MGET_CLEAR
  193. #define MG_MAXALLOC 0x0002
  194. #define MG_ERRPOST  MGET_ERRPOST
  195.  
  196.  
  197. #ifdef __cplusplus
  198. }
  199. #endif
  200.  
  201. #endif
  202.